package com.jhoncy.rapid.base.repository;


import com.jhoncy.rapid.base.pojo.BasePermission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author zhuangqi
 * @date 2017/7/20.
 */
public interface BasePermissionRepository extends JpaRepository<BasePermission,String> {

    List<BasePermission> findBasePermissionsByPermissionIdIn(List<String> permissionIdList);

    @Query(value = "select * from base_permission  where permission_id in (select permission_id from base_role_permission where role_id in (select role_id from base_user_role where user_id = :userId))",nativeQuery=true)
    List<BasePermission> findBasePermissionsByUserId(@Param("userId") String userId);

    @Query(value = "select * from base_permission  where permission_id in (select permission_id from base_role_permission where role_id in (select role_id from base_user_role where user_id = :userId)) and type = :type",nativeQuery=true)
    List<BasePermission> findBasePermissionsByUserIdAndType(@Param("userId") String userId,@Param("type") String type);
}
